package com.wze.wze.Controller;

import com.wze.wze.Entity.ResultEntity;
import com.wze.wze.Service.gzService;
import com.wze.wze.Util.JSONTool;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin //解决跨域
@RestController //控制器注解
@RequestMapping("/Gz/")//请求路径
public class gzController {
    @Resource
    gzService gzService;
    ResultEntity resultEntity = null;

    @GetMapping("UNdelGz")
    private String delGz(@RequestParam("Uid") int Uid, @RequestParam("Sid") int Sid) {
        resultEntity = new ResultEntity();
        try {
            if (gzService.delGzById(Uid,Sid)> 0) {
                resultEntity.setCode("0");
                resultEntity.setMsg("删除成功！");
            } else {
                resultEntity.setCode("1");
                resultEntity.setMsg("删除失败！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            resultEntity.setCode("9999");
            resultEntity.setMsg("系统错误，请联系管理员");
        }
        return JSONTool.getJsonTool().toJson(resultEntity);
    }

    @GetMapping("UNGz")
    private String uniaddGz( @RequestParam("Uid") int Uid, @RequestParam("Sid") int Sid) {
        resultEntity = new ResultEntity();
        try {
            if (gzService.addGz(Uid,Sid) > 0) {
                resultEntity.setCode("0");
                resultEntity.setMsg("添加成功！");
            } else {
                resultEntity.setCode("1");
                resultEntity.setMsg("添加失败！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            resultEntity.setCode("9999");
            resultEntity.setMsg("系统错误，请联系管理员");
        }
        return JSONTool.getJsonTool().toJson(resultEntity);
    }
}
